package com.ck.reactor.ckreactor.exmple;

import com.ck.reactor.ckreactor.domain.User;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname CreateReactor
 * @Description 新增Mono Flux
 * @Date 2021/2/4 14:33
 * @Created by lpc
 */
public class CreateReactor {

    public static void main(String[] args) {

        List<User> userList = new ArrayList<>();
        userList.add(new User(1L, "lipeng", "123456"));
        userList.add(new User(2L, "andy", "123456"));
        userList.add(new User(3L, "mark", "123456"));

        Mono<String> helloWorld = Mono.just("Hello World");
        Flux<String> fewWords = Flux.just("Hello", "World");
        String[] in = {"Hello", "World","test"};
        Flux<User> manyWords = Flux.fromIterable(userList);

        helloWorld.subscribe(s -> {
            System.out.println(s);
        });
        fewWords.doOnNext(s -> {
            System.out.println(s);
        }).subscribe();

        manyWords.subscribe(System.out::println);


        Flux.just("Hello", "World").subscribe(System.out::println);
        Flux.fromArray(new Integer[] {1, 2, 3}).subscribe(System.out::println);
        Flux.empty().subscribe(System.out::println);
        Flux.range(1, 10).subscribe(System.out::println);
        Flux.interval(Duration.of(10, ChronoUnit.SECONDS)).subscribe(System.out::println);
        
//        Flux.intervalMillis(1000).subscribe(System.out::println);



    }




}
